package com.sourcetrip.my.modle;

/**
 * @author: ZhouBert
 * @date: 2020/12/14
 * @description:	二叉树节点
 */
public class TreeNode<E> {

	public E element;
	public TreeNode<E> left;
	public TreeNode<E> right;
	public TreeNode<E> parent;
	public TreeNode(E element, TreeNode<E> parent) {
		this.element = element;
		this.parent = parent;
	}

	/**
	 * 本节点是否时叶子节点
	 * @return
	 */
	public boolean isLeaf() {
		return left == null && right == null;
	}

	/**
	 * 本节点是否有两个子节点
	 * @return
	 */
	public boolean hasTwoChildren() {
		return left != null && right != null;
	}

	/**
	 * 判断本节点是否为 左子节点
	 * @return
	 */
	public boolean isLeftChild(){
		return parent!= null && parent.left == this;
	}

	/**
	 * 判断本节点是否为 右子节点
	 * @return
	 */
	public boolean isRightChild(){
		return parent!= null && parent.right == this;
	}

}
